package lhy.autoparts.servlet;

import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lhy.orm.UniLoader;
import lhy.orm.model.EntityData;

@WebServlet("/EntityTableServlet")
public class EntityTableServlet extends Utf8Servlet {
    /*
    通过实体类来获取表头。
    传入：实体类完整名称 com.cxstock.pojo.XXX
    */
    @Override
    protected void doGet(HttpServletRequest que, HttpServletResponse pon) {
        super.doGet(que, pon);
        String entityClassName = que.getParameter("entityClassName");
        //Class<?> entityClass = ReflectUtils.loadClassByName(ENTITY_CLASS_NAME);
        /*final List<FieldData> fieldDataList = new ArrayList<>();
        ReflectUtils.getAccessibleFieldsList(entityClass).forEach(field -> {
            FieldData sf2 = new FieldData();
            sf2.setFieldName(field.getName());
            sf2.setFieldComment(OrmUtils.getFieldDescription(field));
            sf2.setAutoIncrement(OrmUtils.isFieldAutoIncrement(field));
            sf2.setIdentity(OrmUtils.isFieldIdentity(field));
            sf2.setTypeClassName(ReflectUtils.getClassFullName(field.getType()));
            fieldDataList.add(sf2);
        });*/
        EntityData entityData = UniLoader.entityNameClassMap.get(entityClassName);
        write(pon,entityData.toString());
    }
}
